package icu.wdtt.Interceptors;

import cn.dev33.satoken.interceptor.SaRouteInterceptor;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class AuthorityInterceptor extends SaRouteInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //进行拦截权限!
        SaRouter.match("/files/**",()-> StpUtil.checkPermission("files"));
        SaRouter.match("/user/**",()-> StpUtil.checkPermission("user"));
        SaRouter.match("/role/**",()-> StpUtil.checkPermission("role"));

        //进行角色验证
        SaRouter.match("/admin/**",()->StpUtil.checkRoleOr("管理员"));
        return super.preHandle(request, response, handler);
    }
}
